import django_filters

from users.models import CustomerUser, User, CustomerUserViceInviterRecord
from activities.models import ActivityData, ActivityLevel
from merchants.models import Merchant, MerchantBusinessQRCode, MerchantBusinessQRCodeVisit
from goods.models import LaunchedGoods, Goods
from orders.models import OrderInfo, OrderGoods
from vouchers.models import AliDiscountCouponLevel, AliDiscountCouponInfo, CustomizeActivityLevel, CustomizeActivityFlipCARDS, AliDiscountCouponMerchant
from cashbonus.models import CashActivityLevel, CashActivityData, CashActivityWhiteTable


class OrderInfoFilter(django_filters.rest_framework.FilterSet):
    '''订单过滤'''

    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    order_species = django_filters.BaseInFilter(field_name='order_species', lookup_expr='in')
    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')

    class Meta:
        model = OrderInfo
        fields = ('state', 'create_time_begin', 'create_time_end', 'merchant_id', 'order_species')


class AliDiscountCouponLevelFilter(django_filters.rest_framework.FilterSet):
    '''支付宝活动过滤'''

    coupon_status = django_filters.BaseInFilter(field_name='activity__coupon_status', lookup_expr='in')
    coupon_channel = django_filters.BaseInFilter(field_name='activity__coupon_channel', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponLevel
        fields = ('coupon_status', 'coupon_channel')


class AliDiscountCouponInfoFilter(django_filters.rest_framework.FilterSet):
    '''支付宝活动过滤'''

    status = django_filters.BaseInFilter(field_name='status', lookup_expr='in')
    # coupon_id = django_filters.BaseInFilter(field_name='alidiscountcoupon_level_id', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponInfo
        fields = ('status', )


class GoodsFilter(django_filters.rest_framework.FilterSet):

    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    is_launched = django_filters.BaseInFilter(field_name='is_launched', lookup_expr='in')
    is_use_point = django_filters.BaseInFilter(field_name='is_use_point', lookup_expr='in')
    price_min = django_filters.NumberFilter(field_name="price", lookup_expr='gte')
    price_max = django_filters.NumberFilter(field_name="price", lookup_expr='lte')

    class Meta:
        model = Goods
        fields = ('merchant_id', 'is_use_point', 'price_min', 'price_max', 'is_launched')


class ActivityLevelFilter(django_filters.rest_framework.FilterSet):

    activity_state = django_filters.BaseInFilter(field_name='activity__activity_state', lookup_expr='in')

    class Meta:
        model = ActivityLevel
        fields = ('activity_state', )


class CashActivityLevelFilter(django_filters.rest_framework.FilterSet):

    activity_state = django_filters.BaseInFilter(field_name='cash_activity__activity_state', lookup_expr='in')
    activity_type = django_filters.BaseInFilter(field_name='cash_activity__activity_type', lookup_expr='in')

    class Meta:
        model = CashActivityLevel
        fields = ('activity_type', 'activity_state')


class ActivityDataFilter(django_filters.rest_framework.FilterSet):

    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    activity_level_id = django_filters.BaseInFilter(field_name='activity_level_id', lookup_expr='in')

    class Meta:
        model = ActivityData
        fields = ('state', 'activity_level_id')


class CashActivityDataFilter(django_filters.rest_framework.FilterSet):

    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    # cash_activity_level_id = django_filters.BaseInFilter(field_name='cash_activity_level_id', lookup_expr='in')

    class Meta:
        model = CashActivityData
        fields = ('state', )


class ManagerUserFilter(django_filters.rest_framework.FilterSet):
    '''客户经理料过滤'''

    is_active = django_filters.BaseInFilter(field_name='is_active', lookup_expr='in')
    role_id = django_filters.BaseInFilter(field_name='role_id', lookup_expr='in')

    class Meta:
        model = User
        fields = ('is_active', 'role_id')


class CustomizeActivityLevelFilter(django_filters.rest_framework.FilterSet):

    activity_status = django_filters.BaseInFilter(field_name='customizeactivity__activity_status', lookup_expr='in')
    activity_type = django_filters.BaseInFilter(field_name='customizeactivity__activity_type', lookup_expr='in')

    class Meta:
        model = CustomizeActivityLevel
        fields = ('activity_type', 'activity_status')


class CustomizeActivityFlipCARDSFilter(django_filters.rest_framework.FilterSet):

    open_status = django_filters.BaseInFilter(field_name='open_status', lookup_expr='in')
    customizeactivity_id = django_filters.BaseInFilter(field_name='customizeactivity_id', lookup_expr='in')

    class Meta:
        model = CustomizeActivityFlipCARDS
        fields = ('open_status', 'customizeactivity_id')


class MerchantBusinessQRCodeFilter(django_filters.rest_framework.FilterSet):

    is_c_bind = django_filters.BaseInFilter(field_name='is_c_bind', lookup_expr='in')
    is_achieve = django_filters.BaseInFilter(field_name='is_achieve', lookup_expr='in')
    award_status = django_filters.BaseInFilter(field_name='award_status', lookup_expr='in')

    class Meta:
        model = MerchantBusinessQRCode
        fields = ('is_c_bind', 'is_achieve', 'award_status')


class MerchantBusinessQRCodeVisitFilter(django_filters.rest_framework.FilterSet):
    '''添加用户申请单过滤'''

    qrcode_id = django_filters.BaseInFilter(field_name='qrcode_id', lookup_expr='in')

    class Meta:
        model = MerchantBusinessQRCodeVisit
        fields = ('qrcode_id', )


class CustomerUserViceInviterRecordFilter(django_filters.rest_framework.FilterSet):
    '''添加用户申请单过滤'''

    qrcode_id = django_filters.BaseInFilter(field_name='qrcode_id', lookup_expr='in')

    class Meta:
        model = CustomerUserViceInviterRecord
        fields = ('qrcode_id', )


class OrderGoodsFilter(django_filters.rest_framework.FilterSet):

    is_commented = django_filters.BaseInFilter(field_name='is_commented', lookup_expr='in')
    goods_id = django_filters.BaseInFilter(field_name='goods_id', lookup_expr='in')

    class Meta:
        model = OrderGoods
        fields = ('is_commented', 'goods_id')


class CashActivityWhiteTableFilter(django_filters.rest_framework.FilterSet):

    cashactivity_id = django_filters.BaseInFilter(field_name='cashactivity_id', lookup_expr='in')
    is_admin = django_filters.BaseInFilter(field_name='is_admin', lookup_expr='in')

    class Meta:
        model = CashActivityWhiteTable
        fields = ('cashactivity_id', 'is_admin')


class AliDiscountCouponMerchantFilter(django_filters.rest_framework.FilterSet):

    alidiscountcoupon_id = django_filters.BaseInFilter(field_name='alidiscountcoupon_id', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponMerchant
        fields = ('alidiscountcoupon_id',)